#include <iostream>
#include <cstring>
#include <algorithm>

using namespace std;

const int N = 1010;

int dp[N];
int num[N];
int n;

int main()
{
    cin >> n;
    for (int i = 1; i <= n; i ++ )
    {
        cin >> num[i];
        dp[i] = num[i];
    }

    for (int i = 1; i <= n; i ++ )
        for (int j = 1; j < i; j ++ )
            if (num[i] > num[j]) 
                dp[i] = max(dp[i], dp[j] + num[i]);

    int res = 0;            
    for (int i = 1; i <= n; i ++ )
    {
        res = max(res, dp[i]);
        // cout << dp[i] << " ";
    }
    cout << res << endl;

    return 0;
}